package com.cskaoyan.service;

import com.cskaoyan.bean.Feedback;
import com.cskaoyan.bean.FeedbackExample;
import com.cskaoyan.mapper.FeedbackMapper;
import com.cskaoyan.vo.FeedbackVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能:意见反馈页面
 * 作者:whj
 */
@Service
public class FeedbackServicelmpl implements FeedbackService {

    @Autowired
    FeedbackMapper feedbackMapper;

    @Override
    public FeedbackVo query(Integer page, Integer limit, String username, Integer id, String sort, String order) {
        //分页
        PageHelper.startPage(page,limit);
        //排序
        FeedbackExample feedbackExample = new FeedbackExample();
        feedbackExample.setOrderByClause(sort + " " + order);
        //根据userId,valueId进行精准查询
        FeedbackExample.Criteria criteria = feedbackExample.createCriteria();
        if(id != null && !"".equals(id)){
            criteria.andUserIdEqualTo(id);
        }
        if(username != null && !"".equals(username)){
            criteria.andUsernameLike("%" + username + "%");
        }
        List<Feedback> feedbacks = feedbackMapper.selectByExample(feedbackExample);
        //符合条件的total
        PageInfo<Feedback> feedbackPageInfo = new PageInfo<>(feedbacks);
        long total = feedbackPageInfo.getTotal();
        //返回结果
        FeedbackVo feedbackVo = new FeedbackVo();
        feedbackVo.setItems(feedbacks);
        feedbackVo.setTotal(total);
        return feedbackVo;
    }
}
